package com.itcast.springboot.service.impl;

import com.itcast.springboot.bean.Admin;
import com.itcast.springboot.bean.CommonResult;
import com.itcast.springboot.bean.Forward;
import com.itcast.springboot.mapper.AdminMapper;
import com.itcast.springboot.service.AdminService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional(rollbackFor = Exception.class)
public class AdminServiceImpl implements AdminService {

    @Resource
    private AdminMapper adminMapper;

    @Override
    public Admin getAdminByAcc(String account) {
        return adminMapper.getAdminByAcc(account);
    }

    @Override
    public CommonResult getAdminState(String account, String password) {
        Admin admin = adminMapper.getAdminByAcc(account);
        //状态
        String state = null;
        if (admin == null) {
            state = "用户名错误";
        } else if (!password.equals(admin.getPassword())) {
            state = "密码错误";
        } else {
            state = "登陆成功";
            return new CommonResult<>(200, state, admin);
        }
        return new CommonResult<>(444, state);
    }

    @Override
    //改
    public Integer updatePassword(String account, String password){
        return adminMapper.updatePassword(account, password);
    }
}
